home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / ODUtils / AltPoint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-17  |  5.5 KB  |  211 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        AltPoint.h
  3.  
  4.     Contains:    C++ savvy points and rects (alternate ODPoint, ODRect)
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.  
  12.          <2>     5/24/96    jpa        1.1MRD: pragma internal. Copy ctor & oper=
  13.                                     now inline.
  14.     Notes:
  15.     
  16.     These are alternate definitions of the ODPoint and ODRect structs.
  17.     These definitions have the same size and data format and can be used
  18.     interchangeably with the basic definitions; but they're much more C++
  19.     savvy, with constructors, operators, conversions, and utility methods.
  20.     
  21.     To use these classes instead of the defaults, just include "AltPoint.h"
  22.     as the first thing in your source file. It has to be included first so
  23.     it can override the default struct definitions in PlfmType.h.
  24.     
  25.     This API and implementation are **NOT** an official part of the OpenDoc
  26.     API, just handy utilities for C++ programmers.
  27.     
  28.     In Progress:
  29.         
  30. */
  31.  
  32.  
  33. #ifndef _ALTPOINT_
  34. #define _ALTPOINT_
  35.  
  36. // Make sure that built-in structs do not get defined by PlfmType.h.
  37. #if !defined(SOM_Module_OpenDoc_GeoTypes_defined)
  38.     #define SOM_Module_OpenDoc_GeoTypes_defined
  39. #else
  40.     #error "Must include AltPoint.h *before* ODTypes.h!"
  41. #endif
  42.  
  43.  
  44. #ifndef _ODTYPESF_
  45. #include "ODTypesF.h"        // Must include before ODTypesM.xh
  46. #endif
  47.  
  48. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  49. #include "ODTypesB.xh"        
  50. #endif
  51.  
  52. #ifdef _PLATFORM_MACINTOSH_
  53. #ifndef __TYPES__
  54. #include <Types.h>
  55. #endif
  56. #endif
  57.  
  58. #ifdef PRAGMA_INTERNAL_SUPPORTED
  59. #pragma internal on
  60. #endif
  61.  
  62.  
  63. //==============================================================================
  64. // ODCoordinate
  65. //==============================================================================
  66.  
  67. typedef ODFixed ODCoordinate;
  68.  
  69. //==============================================================================
  70. // ODPoint
  71. //==============================================================================
  72.  
  73. struct ODPoint {
  74.     public:
  75.     
  76.     // CONTENTS:
  77.     
  78.     ODCoordinate x, y;
  79.     
  80.     // CONSTRUCTORS:
  81.     
  82.     ODPoint( ) { }
  83.     
  84.     ODPoint( ODCoordinate xx, ODCoordinate yy )
  85.                     {x=xx; y=yy;}
  86.     
  87.     ODPoint( const ODPoint& pt )                // Copy constructor
  88.                     {x = pt.x; y = pt.y;}
  89.  
  90.     
  91.     // ASSIGNMENT:
  92.     
  93.     ODPoint& operator= ( const ODPoint& pt )    // Copy from another pt
  94.                     {x = pt.x; y = pt.y; return *this;}
  95.     
  96.     // MODIFICATION:
  97.     
  98.     inline void    Clear( )
  99.                     {x=y=0;}
  100.     inline void    Set( ODCoordinate xx, ODCoordinate yy )
  101.                     {x=xx; y=yy;}
  102.     void    Offset( ODCoordinate x, ODCoordinate y );
  103.     void    operator+=( const ODPoint& );
  104.     void    operator-=( const ODPoint& );
  105.     
  106.     // ACCESSORS:
  107.  
  108.     ODSShort    IntX( )        const;        // Returns X-coord as (16bit) integer
  109.     ODSShort    IntY( )        const;        // Returns Y-coord as (16bit) integer
  110.     
  111.     // COMPARISON:
  112.     
  113.     ODBoolean    operator==( const ODPoint& )    const;
  114.     ODBoolean    operator!=( const ODPoint& )    const;
  115.     ODBoolean    ApproxEquals( const ODPoint& )    const;        // to within roundoff error
  116.     
  117.     // MAC TOOLBOX CONVENIENCES:
  118.     
  119. #ifdef _PLATFORM_MACINTOSH_
  120.     ODPoint( Point );                            // Construct from QD point
  121.     ODPoint& operator= ( const Point& );        // Copy from a QD Point
  122.     Point    AsQDPoint( )                    const;    // Convert to integer (QD) point
  123.     void    operator+=( const    Point& );            // Add/subtract QD point
  124.     void    operator-=( const    Point& );
  125. #endif
  126. };
  127.  
  128.  
  129. //==============================================================================
  130. // ODRect
  131. //==============================================================================
  132.  
  133. struct ODRect {
  134.     public:
  135.     
  136.     // CONTENTS:
  137.     
  138.     ODCoordinate left, top, right, bottom;
  139.         
  140.     // CONSTRUCTORS:
  141.     
  142.     ODRect( )        { }
  143.     ODRect( ODCoordinate l, ODCoordinate t,
  144.                   ODCoordinate r, ODCoordinate b )
  145.             {left=l; top=t; right=r; bottom=b; }
  146.     ODRect( const ODPoint&, const ODPoint& );    // Any 2 opposite pts
  147.     ODRect( const ODPoint &topLeft, ODCoordinate width, ODCoordinate height );
  148. #ifdef _PLATFORM_MACINTOSH_
  149.     ODRect( const Rect& );
  150. #endif
  151.     
  152.     // ASSIGNMENT:
  153.     
  154. #ifdef _PLATFORM_MACINTOSH_
  155.     ODRect& operator= ( const Rect& );
  156. #endif
  157.     
  158.     // MODIFICATION:
  159.     
  160.     void    Clear( );
  161.     void    Set( ODCoordinate l, ODCoordinate t, ODCoordinate r, ODCoordinate b );
  162.     void    Set( const ODPoint&, ODCoordinate width, ODCoordinate height );
  163.     void    Set( const ODPoint&, const ODPoint& );    // Any 2 opposite pts
  164.     void    SetInt( short l, short t, short r, short b );
  165.     void    Offset( ODCoordinate x, ODCoordinate y );
  166.     void    Offset( const ODPoint& );
  167.     void    Inset( ODCoordinate x, ODCoordinate y );
  168.     
  169.     void    operator&= ( const ODRect& );    // Intersect with rectangle
  170.     void    operator|= ( const ODRect& );    // Union with rectangle
  171.     void    operator|= ( const ODPoint& );        // Expand to fit point
  172.         
  173.     // ACCESSORS
  174.     
  175.     const ODPoint& TopLeft( )                                        const
  176.                                 {return *(ODPoint*)&left;}
  177.     ODPoint&        TopLeft( )
  178.                                 {return *(ODPoint*)&left;}
  179.     const ODPoint& BotRight( )                                        const
  180.                                 {return *(ODPoint*)&right;}
  181.     ODPoint&        BotRight( )
  182.                                 {return *(ODPoint*)&right;}
  183.     ODCoordinate    Width( )                                        const
  184.                                 {return right-left;}
  185.     ODCoordinate    Height( )                                        const
  186.                                 {return bottom-top;}
  187. #ifdef _PLATFORM_MACINTOSH_
  188.     void            AsQDRect( Rect& )                                const;
  189. #endif
  190.     
  191.     // TESTING
  192.  
  193.     ODBoolean    operator==( const ODRect& )                            const;
  194.     ODBoolean    operator!=( const ODRect &r )                        const
  195.                                 {return !(*this==r);}
  196.     ODBoolean    ApproxEquals( const ODRect &r )                        const;
  197.     
  198.     ODBoolean    IsEmpty( )                                            const;
  199.     ODBoolean    Contains( const ODPoint& )                            const;
  200.     ODBoolean    Contains( const ODRect& )                            const;
  201.     ODBoolean    ApproxContains( const ODRect& )                        const;
  202.     ODBoolean    Intersects( const ODRect& )                            const;
  203. };
  204.  
  205.  
  206. #ifdef PRAGMA_INTERNAL_SUPPORTED
  207. #pragma internal reset
  208. #endif
  209.  
  210. #endif //_ALTPOINT_
  211.